home *** CD-ROM | disk | FTP | other *** search
/ Joystick Magazine 1996 May / cd joy 71No13.iso / pc / demos / eurosoc / source / library / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-22  |  5.9 KB  |  208 lines

  1. /****************************************************************************
  2. *
  3. *  File              : test.c
  4. *  Date Created      : 1/3/95
  5. *  Description       : sample code for the NetNOW! system
  6. *
  7. *  Programmer(s)     : Nick Skrepetos
  8. *  Last Modification : 3/22/95 - 8:28:16 AM
  9. *  Additional Notes  :
  10. *
  11. *****************************************************************************
  12. *            Copyright (c) 1994,  HMI, Inc.  All Rights Reserved            *
  13. ****************************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "hmistd.h"
  19. #include "netnow.h"
  20. #include "vdata.h"
  21. #include "vchat.h"
  22.  
  23. // local functions
  24. VOID    hmiNetworkDemo          ( VOID );
  25.  
  26. /****************************************************************************
  27. *
  28. *  Syntax
  29. *
  30. *     VOID    main( WORD wArgc, PSTR szArgv[] )
  31. *
  32. *  Description
  33. *
  34. *        main function for testing ipx drivers
  35. *
  36. *  Parameters
  37. *
  38. *        Type           Description
  39. *        --------------------------
  40. *        wArgc          Arguement count
  41. *        szArgv         Arguements
  42. *
  43. *  Return
  44. *
  45. *     nothing
  46. *
  47. ****************************************************************************/
  48. VOID    main( WORD wArgc, PSTR szArgv[] )
  49.     {
  50.       // read the .ini file
  51.       if ( !hmiVCHATInit() )
  52.       {
  53.          // print error
  54.          printf( "ERROR: Could not read NETNOW.INI\n" );
  55.  
  56.          // exit
  57.          exit( 1 );
  58.       }
  59.  
  60.       // display message
  61.       printf( "NetNOW! system initialization started.\n" );
  62.  
  63.       // check if NetNOW! is present
  64.       if ( hmiNETNOWInitSystem( 8 ) != _NETNOW_NO_ERROR )
  65.       {
  66.          // print error
  67.          printf( "ERROR: NetNOW! could not locate IPX or NetBIOS!\n" );
  68.  
  69.          // error
  70.          exit( 1 );
  71.       }
  72.  
  73.       // display
  74.       printf( "\nNetNOW! system initialized!\n\n" );
  75.  
  76.       // check for information display
  77.       if ( wNETInfoFlag )
  78.          switch( hmiNETNOWGetNetworkType() )
  79.          {
  80.             case  _NETNOW_IPX    :
  81.                                     // display type
  82.                                     printf( "Network is using a IPX based protocol.\n" );
  83.                                     break;
  84.             case  _NETNOW_NETBIOS:
  85.                                     // display type
  86.                                     printf( "Network is using a NetBIOS based protocol.\n" );
  87.                                     break;
  88.          }
  89.  
  90.       // find nodes
  91.       printf( "\nAttempting to Locate %d Nodes.\n", wNETNodes );
  92.  
  93.       // find the requested nodes
  94.       if ( hmiNETNOWFindNodes( wNETNodes ) )
  95.          printf( "\n\nLocated all requested nodes!\n" );
  96.       else
  97.       {
  98.          printf( "\n\nERROR: could not locate the requested nodes.\n" );
  99.       }
  100.  
  101.       // network demo
  102.       hmiNetworkDemo();
  103.  
  104.       // uninit system
  105.       hmiNETNOWUnInitSystem();
  106.     }
  107.  
  108. /****************************************************************************
  109. *
  110. *  Syntax
  111. *
  112. *     VOID    hmiNetworkDemo( VOID )
  113. *
  114. *  Description
  115. *
  116. *     simple example of sending messages from one machine to another
  117. *
  118. *  Parameters
  119. *
  120. *     none
  121. *
  122. *  Return
  123. *
  124. *     nothing
  125. *
  126. ****************************************************************************/
  127. VOID    hmiNetworkDemo( VOID )
  128.     {
  129.       WORD                 wExitFlag;
  130.       PSTR                 pPacket;
  131.       WORD                 wActiveNodes;
  132.       WORD                 wConsoleNode;
  133.       _XFER_BLOCK_HEADER   sBlock;
  134.       BYTE                 szMessage[ 128 ];
  135.  
  136.       // initialize exit flag
  137.       wExitFlag      =  _FALSE;
  138.  
  139.       // get active nodes
  140.       wActiveNodes   =  hmiNETNOWGetActiveNodes();
  141.  
  142.       // get console node
  143.       wConsoleNode   =  hmiNETNOWGetConsoleNode();
  144.  
  145.       // display banner
  146.       printf( "\n\n*********  NetNOW! Demonstration *********\n\n" );
  147.  
  148.       // display console node
  149.       printf( "Number of Active Nodes       : %d\n", wActiveNodes );
  150.       printf( "Node Number of this Computer : %d\n", wConsoleNode );
  151.  
  152.       // display message
  153.       printf( "\n(S)end to station, (Q)uit\n" );
  154.  
  155.       // wait for exit flag
  156.       while( !wExitFlag )
  157.       {
  158.          // check if we have data
  159.          if ( hmiNETNOWGetHeader( (PSTR)&sBlock, sizeof( _XFER_BLOCK_HEADER ), &pPacket ) )
  160.          {
  161.             // check header type
  162.             switch( sBlock.wType )
  163.             {
  164.                case  _XFER_BLOCK_DATA  :
  165.                                           // get data block
  166.                                           hmiNETNOWGetBlock( pPacket, szMessage, sBlock.wLength );
  167.  
  168.                                           // print message
  169.                                           printf( "%s\n", szMessage );
  170.                                           break;
  171.             }
  172.  
  173.             // post listen
  174.             hmiNETNOWPostListen();
  175.          }
  176.  
  177.          // check for key press
  178.          if ( kbhit() )
  179.             switch( tolower( getch() ) )
  180.             {
  181.                case  's'   :
  182.                               // set up header type
  183.                               sBlock.wType   =  _XFER_BLOCK_DATA;
  184.  
  185.                               // display
  186.                               printf( "Enter Message : \n" );
  187.  
  188.                               // get message
  189.                               gets( szMessage );
  190.  
  191.                               // set block length
  192.                               sBlock.wLength =  strlen( szMessage ) + 1;
  193.  
  194.                               // send data
  195.                               while( !hmiNETNOWSendData( (PSTR)&sBlock, sizeof( _XFER_BLOCK_HEADER ), (PSTR)szMessage,
  196.                                       sBlock.wLength, wConsoleNode ^ 0x01 ) );
  197.                               break;
  198.                case  'q'   :
  199.                               // set exit flag
  200.                               wExitFlag   =  _TRUE;
  201.                               break;
  202.             }
  203.       }
  204.         
  205.     }
  206.  
  207.  
  208.